package com.alm.token.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.InputType;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alm.token.ConStant;
import com.alm.token.MyApp;
import com.alm.token.R;
import com.alm.token.apinew.RetrofitUtil;
import com.alm.token.base.BaseActivity;
import com.alm.token.ui.data.bean.CurrentOrderData;
import com.alm.token.ui.data.bean.RegisterData;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.ui.view.RegisterView;
import com.alm.token.utils.ActionBarHelper;
import com.alm.token.utils.LogUtil;
import com.alm.token.utils.MyOnclickListener;
import com.alm.token.utils.PopupAdapter;
import com.alm.token.utils.SpUtil;
import com.alm.token.utils.StringUtils;
import com.alm.token.utils.Utils;
import com.alm.token.widget.CommonPopupWindow;
import com.alm.token.widget.Countdownbutton;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import baibeiwallet.utils.DialogUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnFocusChange;

import static com.alm.token.ConStant.county;
import static com.alm.token.ConStant.countyID;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_CODE_VAULE;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_INTO_CODE;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_NAME_VAULE;
import static com.alm.token.ui.activity.FundArealistActivity.INTENT_RESULT_SUCC_CODE;
import static com.alm.token.ui.persenter.MyPreenter.update_password;

public class FindPwdActivity extends BaseActivity implements RegisterView<RegisterData>, CommonPopupWindow.ViewInterface {


    @BindView(R.id.edt_inputusername)
    EditText edtInputusername;
    @BindView(R.id.edt_inputoldpsw)
    EditText getEdtInputoldpsw;
    @BindView(R.id.edt_inputpswone)
    EditText edtInputpswone;
    @BindView(R.id.edt_inputpswonce)
    EditText edtInputpswonce;
    @BindView(R.id.edt_inputauthCode)
    EditText edtInputauthCode;
    @BindView(R.id.edt_inputphone)
    EditText edtInputphone;
    @BindView(R.id.edt_inputcode)
    EditText edtInputcode;
    //    @BindView(R.id.tv_getcode)
//    TextView tvGetcode;
    @BindView(R.id.tv_getcode)
    Countdownbutton tvGetcode;
    @BindView(R.id.tv_setphonecode)
    TextView tvSetphonecode;
    @BindView(R.id.tv_clickphonecountry)
    TextView tvClickphonecountry;
    @BindView(R.id.tv_mail)
    TextView tv_mail;
    @BindView(R.id.tv_pswsubmit)
    TextView tvPswsubmit;
    @BindView(R.id.rly_userbanebody)
    RelativeLayout rlyUserbanebody;
    @BindView(R.id.rly_oldpswbody)
    RelativeLayout rlyOldpswbody;
    @BindView(R.id.rly_authcodebody)
    RelativeLayout rlyAuthcodebody;
    @BindView(R.id.ly_changepsw_body)
    LinearLayout ly_changepsw_body;
    @BindView(R.id.ly_findpsw_body)
    LinearLayout ly_findpsw_body;
    @BindView(R.id.edt_inputmonic)
    EditText edt_inputmonic;
    @BindView(R.id.edt_inputnewpsw)
    EditText edt_inputnewpsw;
    @BindView(R.id.edt_inputnewpswonce)
    EditText edt_inputnewpswonce;
    @BindView(R.id.tv_changehost)
    TextView tv_changehost;
    private String strUserName, strPhone, strCode, stroldPswone, strPswone, strPswonce, strAuthCode, strinviteCode, strMonic;
    private String[] countys = new String[14];

    private int type = 0;
    public static int changeLoginPswtype = 1;

    @Override
    protected MyPreenter initPreenter() {
//        MyApp.mOkHttpClient = null;
//        RetrofitUtil.getInstance().setInstance();

        return new MyPreenter(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_find_pwd;
    }

    @Override
    protected void initVariables() {
        for (int i = 0; i < countys.length; i++) {
            countys[i] = getResources().getString(county[i]);
        }
        type = getIntent().getIntExtra("FindPwdActivity_type", 0);
    }

    @Override
    protected void initViews() {

        if (type == changeLoginPswtype) {
            ly_changepsw_body.setVisibility(View.VISIBLE);
            ly_findpsw_body.setVisibility(View.GONE);
            rlyUserbanebody.setVisibility(View.GONE);
            rlyAuthcodebody.setVisibility(View.GONE);
            rlyOldpswbody.setVisibility(View.VISIBLE);
            new ActionBarHelper(this).setTitle(getString(R.string.paypasw_title_changeloginpsw));
//            if (MyApp.getUserData() != null && MyApp.getUserData().getData() != null && MyApp.getUserData().getData().getUser() != null) {
//                String strPhone = MyApp.getUserData().getData().getUser().getPhone();
//                edtInputphone.setText(strPhone.length() > 6 ? strPhone.substring(0, 3) + "****" + strPhone.substring(strPhone.length() - 4, strPhone.length()) : strPhone);
//                edtInputphone.setEnabled(false);
//            }
        } else {
            ly_changepsw_body.setVisibility(View.GONE);
            ly_findpsw_body.setVisibility(View.VISIBLE);
            rlyUserbanebody.setVisibility(View.GONE);
            rlyAuthcodebody.setVisibility(View.GONE);
            rlyOldpswbody.setVisibility(View.GONE);
            new ActionBarHelper(this).setTitle(getString(R.string.title_hint_item3));
            tv_changehost.setOnClickListener(this);
        }
        tv_mail.setText(StringUtils.nullToStr(MyApp.getMail()));
        if (MyApp.getMail() != null) {
            String[] split = MyApp.getMail().split("@");
            tv_mail.setText(split[0].length() > 4 ? split[0].substring(0, 2) + "****" + split[0].substring(split[0].length() - 2, split[0].length()) + "@" + split[1] : MyApp.getMail());
        }

        tvPswsubmit.setOnClickListener(this);
        tvGetcode.setOnClickListener(this);
        tvClickphonecountry.setOnClickListener(this);

    }

    @Override
    protected void loadData() {
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_changehost:
                if (edt_inputmonic.getText().toString().equalsIgnoreCase("cc")
                        && edt_inputnewpsw.getText().toString().equalsIgnoreCase("cc")
                        && edt_inputnewpswonce.getText().toString().equalsIgnoreCase("cc")) {
                    if(ConStant.ISDEBUG){
                        showPopupMenu(tv_changehost);
                    }

                }
                break;
            case R.id.tv_clickphonecountry:
//                showPopupMenu2(tvSetphonecode);
//                showDownPop(tvSetphonecode);
                startActivityForResult(FundArealistActivity.class, INTENT_RESULT_INTO_CODE);

                break;

            case R.id.tv_pswsubmit:
                if (type == changeLoginPswtype) {
                    if (edtInputusername.getText().toString().isEmpty() && type != changeLoginPswtype) {
                        showToast(getString(R.string.profile_hint_warn8));
                        edtInputusername.setFocusable(true);
                        edtInputusername.setFocusableInTouchMode(true);
                        edtInputusername.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edtInputusername, 0);
                        break;
                    }

                    if (getEdtInputoldpsw.getText().toString().isEmpty() && type == changeLoginPswtype) {
                        showToast(getString(R.string.paypasw_hint_inputoldloginpsw));
                        getEdtInputoldpsw.setFocusable(true);
                        getEdtInputoldpsw.setFocusableInTouchMode(true);
                        getEdtInputoldpsw.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(getEdtInputoldpsw, 0);
                        break;
                    }
                    if (edtInputpswone.getText().toString().isEmpty()) {
                        showToast(getString(R.string.profile_hint_warn9));
                        edtInputpswone.setFocusable(true);
                        edtInputpswone.setFocusableInTouchMode(true);
                        edtInputpswone.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edtInputpswone, 0);
                        break;
                    }
                    if (edtInputpswonce.getText().toString().isEmpty()) {
                        showToast(getString(R.string.profile_hint_warn10));
                        edtInputpswonce.setFocusable(true);
                        edtInputpswonce.setFocusableInTouchMode(true);
                        edtInputpswonce.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edtInputpswonce, 0);
                        break;
                    }
//                if (edtInputphone.getText().toString().isEmpty()) {
//                    showToast(getString(R.string.profile_hint_warn6));
//                    edtInputphone.setFocusable(true);
//                    edtInputphone.setFocusableInTouchMode(true);
//                    edtInputphone.requestFocus();
//                    //显示软键盘
////                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
//                    //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
//                    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
//                    imm.showSoftInput(edtInputphone, 0);
//                    break;
//                }
                    if (edtInputcode.getText().toString().isEmpty()) {
                        showToast(getString(R.string.profile_hint_warn11));
                        edtInputcode.setFocusable(true);
                        edtInputcode.setFocusableInTouchMode(true);
                        edtInputcode.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edtInputcode, 0);
                        break;
                    }
//                if (edtInputauthCode.getText().toString().isEmpty() && type != changeLoginPswtype) {
//                    showToast(getString(R.string.findpasw_hint_inputauthCode));
//                    edtInputauthCode.setFocusable(true);
//                    edtInputauthCode.setFocusableInTouchMode(true);
//                    edtInputauthCode.requestFocus();
//                    //显示软键盘
////                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
//                    //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
//                    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
//                    imm.showSoftInput(edtInputauthCode, 0);
//                    break;
//                }

                    strUserName = edtInputusername.getText().toString();
                    strPhone = edtInputphone.getText().toString();
                    strCode = edtInputcode.getText().toString();
                    stroldPswone = getEdtInputoldpsw.getText().toString();
                    strPswone = edtInputpswone.getText().toString();
                    strPswonce = edtInputpswonce.getText().toString();
                    strAuthCode = edtInputauthCode.getText().toString();
                    if (!strPswone.equals(strPswonce)) {
                        showToast(getString(R.string.profile_hint_warn13));
                        break;
                    }

                    if (!Utils.verifyUserName(strUserName) && type != changeLoginPswtype) {
                        showToast(getString(R.string.profile_hint_warn2));
                        break;
                    }
                    if ((strUserName.length() < 4 || strUserName.length() > 18) && type != changeLoginPswtype) {
                        showToast(getString(R.string.profile_hint_warn3));
                        break;
                    }
//                if (!(strUserName.substring(0)
//                        + strUserName.substring(strUserName.length() - 1))
//                        .matches("[0-9A-Za-z]*")) {
//                    showToast(getString(R.string.profile_hint_warn4));
//                    break;
//                }

                    if (!Utils.verifyUserNameFL(strUserName) && type != changeLoginPswtype) {//[A-Za-z1-9]{2}
                        showToast(getString(R.string.profile_hint_warn4));
                        break;
                    }

//                if (!Utils.verifyUserNameFL(stroldPswone) && type == changeLoginPswtype) {//[A-Za-z1-9]{2}
//                    showToast(getString(R.string.profile_hint_warn44) + "\n" + getString(R.string.paypasw_hint_inputoldloginpsw));
//                    break;
//                }

                    if (strPswone.length() < 8 || strPswone.length() > 20) {
                        showToast(getString(R.string.profile_hint_warn33));
                        break;
                    }
                    if (!Utils.verifyUserNameFL(strPswone)) {//[A-Za-z1-9]{2}
                        showToast(getString(R.string.profile_hint_warn44));
                        break;
                    }
                    if (!Utils.verifyUserPsw(strPswone)) {
                        showToast(getString(R.string.profile_hint_warn22));
                        break;
                    }
                } else {
                    if (edt_inputmonic.getText().toString().isEmpty()) {
                        showToast(getString(R.string.findpsw_hint_inputmonic_warm));
                        edt_inputmonic.setFocusable(true);
                        edt_inputmonic.setFocusableInTouchMode(true);
                        edt_inputmonic.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edt_inputmonic, 0);
                        break;
                    }
                    if (edt_inputnewpsw.getText().toString().isEmpty()) {
                        showToast(getString(R.string.paypasw_hint_inputnewloginpsw));
                        edt_inputnewpsw.setFocusable(true);
                        edt_inputnewpsw.setFocusableInTouchMode(true);
                        edt_inputnewpsw.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edt_inputnewpsw, 0);
                        break;
                    }
                    if (edt_inputnewpswonce.getText().toString().isEmpty()) {
                        showToast(getString(R.string.paypasw_hint_inputnewloginpswonce));
                        edt_inputnewpswonce.setFocusable(true);
                        edt_inputnewpswonce.setFocusableInTouchMode(true);
                        edt_inputnewpswonce.requestFocus();
                        //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                        //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                        InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(edt_inputnewpswonce, 0);
                        break;
                    }
                    if (!edt_inputnewpswonce.getText().toString().equals(edt_inputnewpsw.getText().toString())) {
                        showToast(getString(R.string.profile_hint_warn13));
                        break;
                    }

                    strPswone = edt_inputnewpsw.getText().toString();
                    strMonic = edt_inputmonic.getText().toString();
                    if (strPswone.length() < 8 || strPswone.length() > 20) {
                        showToast(getString(R.string.profile_hint_warn33));
                        break;
                    }
                    if (!Utils.verifyUserNameFL(strPswone)) {//[A-Za-z1-9]{2}
                        showToast(getString(R.string.profile_hint_warn44));
                        break;
                    }
                    if (!Utils.verifyUserPsw(strPswone)) {
                        showToast(getString(R.string.profile_hint_warn22));
                        break;
                    }
                }
                if (type == changeLoginPswtype) {
                    preenter.getmodfixMyPwdData(stroldPswone, strPswone, strPswonce, strCode);
                } else {
                    preenter.getmodfixMyPwdData(strPswone, strMonic);
                }

//                preenter.getmodfixMyPwdData("+" + Integer.parseInt(tvSetphonecode.getText().toString()) + strPhone, strPswone, strCode, strUserName);
//                preenter.getmodfixMyPwdData(strPhone, strPswone, strCode, strUserName);
                break;

            case R.id.tv_getcode:
//                if (type == changeLoginPswtype) {
//                    if (MyApp.getUserData() != null && MyApp.getUserData().getData() != null && MyApp.getUserData().getData().getUser() != null) {
//                        strPhone = MyApp.getUserData().getData().getUser().getPhone();
//                    }
//                } else {
//                    strPhone = edtInputphone.getText().toString();
//                }
//                if (strPhone.isEmpty()) {
//                    showToast(getString(R.string.profile_hint_warn6));
//                    edtInputphone.setFocusable(true);
//                    edtInputphone.setFocusableInTouchMode(true);
//                    edtInputphone.requestFocus();
//                    //显示软键盘
////                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
//                    //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
//                    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
//                    imm.showSoftInput(edtInputphone, 0);
//                    break;
//                } else if (!Utils.isPhoneNumberValid("+" + Integer.parseInt(tvSetphonecode.getText().toString()) + strPhone,
//                        Integer.parseInt(tvSetphonecode.getText().toString()) + "")) {
//
//                    showToast(getString(R.string.profile_hint_warn7));
//                    edtInputphone.setFocusable(true);
//                    edtInputphone.setFocusableInTouchMode(true);
//                    edtInputphone.requestFocus();
//                    //显示软键盘
////                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
//                    //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
//                    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
//                    imm.showSoftInput(edtInputphone, 0);
//                    break;
//                }
                tvGetcode.start();
                String Key = type == changeLoginPswtype ? update_password : MyPreenter.back_password;
                LogUtil.d("9999验证码" + "+" + Integer.parseInt(tvSetphonecode.getText().toString()) + strPhone);
//                preenter.getSmsCodeData(strPhone, Key, Integer.parseInt(tvSetphonecode.getText().toString()) + "");
                preenter.getSmsCodeData(MyApp.getMail(), update_password);
                break;
            default:
                break;
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == INTENT_RESULT_INTO_CODE && resultCode == INTENT_RESULT_SUCC_CODE && data != null) {
            String name = data.getStringExtra(INTENT_RESULT_NAME_VAULE);
            String code = data.getStringExtra(INTENT_RESULT_CODE_VAULE);
            LogUtil.e("name=" + name + "  code=" + code);

            tvSetphonecode.setText(code);
            tvClickphonecountry.setText(name);
        }
    }

    @OnFocusChange({R.id.edt_inputphone, R.id.edt_inputcode,
            R.id.edt_inputpswone, R.id.edt_inputpswonce})
    void onEdiFocusChange(View view, boolean hasFocus) {
        switch (view.getId()) {
            case R.id.edt_inputphone:

                break;

            case R.id.edt_inputcode:

                break;
            case R.id.edt_inputpswone:
                if (hasFocus && edtInputusername.getText().toString().isEmpty() && type != changeLoginPswtype) {
                    showToast(getString(R.string.profile_hint_warn8));
                    edtInputusername.setFocusable(true);
                    edtInputusername.setFocusableInTouchMode(true);
                    edtInputusername.requestFocus();
                    //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(edtInputusername, 0);
                    break;
                }
                break;
            case R.id.edt_inputpswonce:
                if (hasFocus && edtInputusername.getText().toString().isEmpty() && type != changeLoginPswtype) {
                    showToast(getString(R.string.profile_hint_warn8));
                    edtInputusername.setFocusable(true);
                    edtInputusername.setFocusableInTouchMode(true);
                    edtInputusername.requestFocus();
                    //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(edtInputusername, 0);
                    break;
                }
                if (hasFocus && edtInputpswone.getText().toString().isEmpty()) {
                    showToast(getString(R.string.profile_hint_warn9));
                    edtInputpswone.setFocusable(true);
                    edtInputpswone.setFocusableInTouchMode(true);
                    edtInputpswone.requestFocus();
                    //显示软键盘
//                     this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    //如果上面的代码没有弹出软键盘 可以使用下面另一种方式
                    InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.showSoftInput(edtInputpswone, 0);
                    break;
                }
                break;
        }


    }

    @Override
    public void getData(RegisterData registerData) {
        showToast(registerData.getMsg());
        if (registerData.getStatus() == 0)
            finish();
    }

    @Override
    public void jumpToLoginAct(int staue) {
        if (staue == 3) {
//            showToast(getString(R.string.common_relogin));
//            Intent intent = new Intent();
//            intent.setAction(ConStant.EXIT_APP);
//            sendBroadcast(intent);
//            startActivity(BlockWalletLoginActivity.class);
//            finish();
        } else if (staue == 4) {
//            showToast(getString(R.string.paypasw_hint_setpaypsw));
//            Intent intent = new Intent(this, PayPwdActivity.class);
//            intent.putExtra("PayPwdActivityType", PayPwdActivity.PAYPSW_SET);
//            startActivity(intent);
//            finish();
            showToSetPaypswDialog();
        } else if (staue == 666) {
            showToUpdata();
        }
    }

    @Override
    public void onError(String error) {
        showToast(getString(R.string.common_loaderrritry));
    }

    @Override
    public void ShowProgress() {
        showWaitDialog(getString(R.string.profile_hint_warn17));
    }

    @Override
    public void hideProgress() {
        hideWaitDialog();
    }

    @Override
    public void getCode(RegisterData registerData) {
//        if (registerData.getMsg().equalsIgnoreCase(getString(R.string.profile_hint_warn15))) {
//            showToast(getString(R.string.profile_hint_warn14));
//        } else {
//            showToast(registerData.getMsg());
//        }
        showToast(registerData.getMsg());
    }

    @Override
    public void getcreateCode(Bitmap bitmap) {

    }


    private CommonPopupWindow popupWindow;

    //向下弹出
    public void showDownPop(View view) {
        if (countrys.size() == 0) {
            for (int i = 0; i < countys.length; i++) {
                countrys.add(countys[i]);
                countryMap.put(countys[i], countyID[i]);
            }
        }
        if (popupWindow != null && popupWindow.isShowing()) return;
        popupWindow = new CommonPopupWindow.Builder(this)
                .setView(R.layout.popup_down)
                .setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
                .setAnimationStyle(R.style.AnimDown)
                .setViewOnclickListener(this)
                .setOutsideTouchable(true)
                .create();
        popupWindow.showAsDropDown(view);
        //得到button的左上角坐标
//        int[] positions = new int[2];
//        view.getLocationOnScreen(positions);
//        popupWindow.showAtLocation(findViewById(android.R.id.content), Gravity.NO_GRAVITY, 0, positions[1] + view.getHeight());
    }

    public List<String> countrys = new ArrayList<>();
    public Map<String, String> countryMap = new HashMap<>();

    @Override
    public void getChildView(View view, int layoutResId) {
        //获得PopupWindow布局里的View
        switch (layoutResId) {
            case R.layout.popup_down:
                RecyclerView recycle_view = (RecyclerView) view.findViewById(R.id.recycle_view);
                recycle_view.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
//                recycle_view.setLayoutManager(new GridLayoutManager(this, 3));
                PopupAdapter mAdapter = new PopupAdapter(this, countrys);
                recycle_view.setAdapter(mAdapter);
                mAdapter.setOnItemClickListener(new MyOnclickListener() {
                    @Override
                    public void onItemClick(View view, int position) {
//                        showToast("position is " + position);
                        tvSetphonecode.setText(countryMap.get(countrys.get(position)));
                        tvClickphonecountry.setText(countrys.get(position));
                        if (popupWindow != null) {
                            popupWindow.dismiss();
                        }
                    }
                });
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


    public void showPopupMenu(View view) {
        //参数View 是设置当前菜单显示的相对于View组件位置，具体位置系统会处理
        PopupMenu popupMenu = new PopupMenu(this, view);
        //加载menu布局

        Menu menu = popupMenu.getMenu();

        menu.add("正式服");
        menu.add("测试服");
        menu.add("法建");
        menu.add("郭宇");
        menu.add("啊应");


        popupMenu.getMenuInflater().inflate(R.menu.menu_popmenu, menu);

        //设置menu中的item点击事件
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getTitle().toString().equalsIgnoreCase("正式服")) {

                    DialogUtils.enterHost(FindPwdActivity.this, item.getTitle(),ConStant.HOST_serv, InputType.TYPE_CLASS_TEXT, (pwd) -> {
                        SpUtil.putInt(MyApp.context, ConStant.HOSTTYPE, 0);
                        SpUtil.putString(MyApp.context, ConStant.HOSTTYPE+0, pwd);
                        ConStant.HOST = pwd;
                        RetrofitUtil.getInstance().setInstance();
//                        jumpToLoginAct(3);
                        startActivity(SplashActivity.class);
                    });

                } else if (item.getTitle().toString().equalsIgnoreCase("测试服")) {

                    DialogUtils.enterHost(FindPwdActivity.this, item.getTitle(),ConStant.HOST_test, InputType.TYPE_CLASS_TEXT, (pwd) -> {
                        SpUtil.putInt(MyApp.context, ConStant.HOSTTYPE, 1);
                        SpUtil.putString(MyApp.context, ConStant.HOSTTYPE+1, pwd);
                        ConStant.HOST = pwd;
                        RetrofitUtil.getInstance().setInstance();
//                        jumpToLoginAct(3);
                        startActivity(SplashActivity.class);
                    });
                } else if (item.getTitle().toString().equalsIgnoreCase("法建")) {
                    DialogUtils.enterHost(FindPwdActivity.this, item.getTitle(),ConStant.HOST_ip, InputType.TYPE_CLASS_TEXT, (pwd) -> {
                        SpUtil.putInt(MyApp.context, ConStant.HOSTTYPE, 2);
                        SpUtil.putString(MyApp.context, ConStant.HOSTTYPE+2, pwd);
                        ConStant.HOST = pwd;
                        RetrofitUtil.getInstance().setInstance();
//                        jumpToLoginAct(3);
                        startActivity(SplashActivity.class);
                    });

                } else if (item.getTitle().toString().equalsIgnoreCase("郭宇")) {
                    DialogUtils.enterHost(FindPwdActivity.this, item.getTitle(),ConStant.HOST_ip1, InputType.TYPE_CLASS_TEXT, (pwd) -> {
                        SpUtil.putInt(MyApp.context, ConStant.HOSTTYPE, 3);
                        SpUtil.putString(MyApp.context, ConStant.HOSTTYPE+3, pwd);
                        ConStant.HOST = pwd;
                        RetrofitUtil.getInstance().setInstance();
//                        jumpToLoginAct(3);
                        startActivity(SplashActivity.class);
                    });

                } else if (item.getTitle().toString().equalsIgnoreCase("啊应")) {
                    DialogUtils.enterHost(FindPwdActivity.this, item.getTitle(),ConStant.HOST_ip2, InputType.TYPE_CLASS_TEXT, (pwd) -> {
                        SpUtil.putInt(MyApp.context, ConStant.HOSTTYPE, 4);
                        SpUtil.putString(MyApp.context, ConStant.HOSTTYPE+4, pwd);
                        ConStant.HOST = pwd;
                        RetrofitUtil.getInstance().setInstance();
//                        jumpToLoginAct(3);
                        startActivity(SplashActivity.class);
                    });

                }
                return true;
            }
        });
        popupMenu.show();
    }
}
